package app.web.admin.service.impl;

import app.web.admin.domain.ao.MenuPatchByIdAo;
import app.web.admin.domain.pojo.AdminMenu;
import app.web.admin.mapper.AdminMenuMapper;
import app.web.admin.service.MenuService;
import com.gitee.feizns.quickstart.web.ex.ServiceException;
import com.gitee.feizns.quickstart.web.restful.Rests;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 权限服务实现
 * @author feizns
 * @since 2025-04-09
 */
@Service
@RequiredArgsConstructor
public class MenuServiceImpl implements MenuService {

    /**
     * 权限 Mapper
     */
    private final AdminMenuMapper mapper;

    @Override
    public AdminMenu patchById(Long id, MenuPatchByIdAo ao) {
        AdminMenu adminMenu = Rests.getById(AdminMenu.class, id);
        if ( !adminMenu.uniqueColumnValueIsUpdatable(AdminMenu::getIdentifier, ao.getIdentifier()) )
            throw new ServiceException("权限标识符已存在.");
        adminMenu.updateById();
        return adminMenu;
    }

}
